import * as DT from 'dt-sdk/library/DT'
import { viewer } from '@/components/dt-scene/index.vue'
import MeasureLength from '@/utils/plotsAnalysisUnit/plotShapes/MeasureLength.js'
import MeasurePolygon from '@/utils/plotsAnalysisUnit/plotShapes/MeasurePolygon.js'
import DrownTool from '@/utils/plotsAnalysisUnit/plotShapes/DrownAnalysis.js'
import {addContourLine, removeContourLine} from "@/utils/dt-sdk/contourLine.js"
let measureLength = undefined
let measurePolygon = undefined
let drownTarget = undefined

export default {
  name: 'AnalysisPot',
  // components: {plot, auxiliary},
  data() {
    return {
      // toolVisible: {
      //   threeAnalysis: false,
      //   militaryPlot: false,
      //   assistTool: false
      // }
      // measureLength: undefined,
      // measurePolygon: undefined,
      // drownTarget: null
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
    let interval = setInterval(() => {
      if (viewer) {
        // this.initPlot(window.viewer, DT.Cesium)
        this.initMeasureLength(viewer, DT.Cesium)
        this.initMeasurePolygon(viewer, DT.Cesium)
        clearInterval(interval)
      }
    }, 1000)
    
  },
  destroyed() { },
  methods: {
    initMeasureLength(viewer, Cesium){
      measureLength = new MeasureLength({
        viewer:viewer,
        Cesium:Cesium,
        callback:(data) =>{
          console.log(data)
          this.$emit('setDialogText', data)
        }
      })
      
    },
    initMeasurePolygon(viewer, Cesium){
      measurePolygon = new MeasurePolygon({
        viewer:viewer,
        Cesium:Cesium,
        callback:(data) =>{
          console.log(data)
          this.$emit('setDialogText', data)
        }
      })

    },
    startMeasure(){
      measureLength.startCreate({
        color: 'fff',
        
      })
    },
    startMeasure2(){

      measurePolygon.startCreate({
        color: 'fff',
        outLineColor: 'fff',
        flag: true
      })
    },
    startDrown () {
      let params = {
        viewer: viewer,
        Cesium: DT.Cesium,
      }
      drownTarget = new DrownTool(params)
      drownTarget.init()
    },
    contourLine(){
      if(!viewer.cesiumViewer.scene.globe.material){
        addContourLine(viewer)
      }else{
        removeContourLine(viewer)
      }
    }
  },
}